package com.jiuyun.dao.impl;

import com.jiuyun.dao.StudentDao;
import com.jiuyun.entity.Student;
import com.jiuyun.util.AliPool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class StudentDaoImpl implements StudentDao {

    @Override
    public List getList() throws SQLException {
        String sql="select * from student";
        List list = new ArrayList();
        Connection conn = AliPool.getConn();
        PreparedStatement pt = conn.prepareStatement(sql);
        ResultSet rs =  pt.executeQuery();
        while(rs.next()){
            int stid =rs.getInt(1);
            String name =rs.getString(3);
            list.add(new Student(stid,name));
        }
        conn.close();
        return list;
    }
}
